﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using TpExtensions;

namespace TpBaseObjects.Base {
    public class ProjektWorkbook {

        #region Members

        private List<ProjectSheet> mySheetList = new List<ProjectSheet>();
        private List<Worksheet> mySheets = new List<Worksheet>();
        private Workbook myWb;
        private int projectNumber;

        #endregion

        #region Constructor

        public ProjektWorkbook() {
        }

        public ProjektWorkbook(int projectNumber, Workbook wb)
            : this() {
            myWb = wb;
            this.projectNumber = projectNumber;
            try {
                foreach (Worksheet sh in wb.Sheets) {
                    ProjectSheet sheet = new ProjectSheet(sh, false);
                    if (sheet.ProjektNummer == projectNumber) {
                        mySheetList.Add(sheet);
                        mySheets.Add(sh);
                    }
                }
            } catch {
                //do nothing
            }
        }

        #endregion

        #region Properties

        public bool IsBusiness {
            get {
                bool ret = false;
                byte lenName = Convert.ToByte(myWb.Name.Length - 5);
                string t1 = myWb.Name.ToString().Left(lenName).Right(4);
                if (t1.IsNumeric(System.Globalization.NumberStyles.Any)) {
                    ret = true;
                }
                return ret;
            }
        }

        public string MyFileName {
            get {
                byte lenName = Convert.ToByte(myWb.Name.Length - 5);
                string t1 = myWb.Name.ToString().Left(lenName);
                string ret = t1.Right(3);

                if (this.IsBusiness) {
                    ret = t1.Right(4);
                }
                //ret = ret.Left(2) + (IsBusiness ? this.projectNumber.ToString("00") : this.projectNumber.ToString());
                return ret;
            }
        }

        public List<ProjectSheet> ProjektSheets {
            get { return mySheetList; }
        }

        public List<Worksheet> WbSheets {
            get { return mySheets; }
        }



        #endregion

        #region Functions

        public Sheets MySheets() {
            return myWb.Sheets;
        }

        #endregion

    }
}
